package com.heima.article.controller.v1;

import com.heima.article.service.ArticleHomeService;
import com.heima.common.constans.ArticleConstants;
import com.heima.model.article.dtos.ArticleDto;
import com.heima.model.article.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 文章列表首页
 */
@RestController
@RequestMapping("/api/v1/article")
public class ArticleHomeController {

    @Resource
    private ArticleHomeService articleHomeService;
    /**
     * 查询首页
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody ArticleHomeDto dto){
        return articleHomeService.load2(dto);
    }

    /**
     * 下拉加载更新
     * @param dto
     * @return
     */
    @PostMapping("/loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto dto){
        return articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 上拉，加载更多
     * @param dto
     * @return
     */
    @PostMapping("/loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto dto){
        return articleHomeService.load(dto, ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 保存app端文章三剑客的操作
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody ArticleDto dto){
        return articleHomeService.save(dto);
    }
}
